package com.blog.study.study6;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * 测试StreamApi.
 *
 * @author 张俊强~.
 * @date 2017/11/29-17:37.
 */
public class TestStreamApi {

    public static void main(String[] args) {
        //对集合功能的增强

        List<String> strList = new ArrayList<>();
        strList.add("aaa");
        strList.add("aaffa");
        strList.add("bbb");
        strList.add("bbb12345");
        strList.add("2345678987654345678");
//        Stream<String> stringStream=strList.stream().filter((String str)-> str.length()<10);//filter中间操作
//        Stream<String> stringStream=strList.stream().sorted((String s1,String s2)-> s1.length()>s2.length()?1:-1);
//        int i = 100000;
//        Stream<String> stringStream = null;
//        Date s=new Date();
//        while (i-- != 0) {
////            stringStream = strList.stream().map((String str) -> "{" + str + "]");
//            for(int j=0;j<strList.size();j++){
//                String str=strList.get(j);
//                str="{" + str + "]";
//                strList.set(j,str);
//            }
//        }
//        Date e=new Date();
// System.out.println((e.getTime() - s.getTime()));
//        boolean flag=strList.stream().anyMatch((String str)->str.startsWith("a"));
//        flag=strList.stream().allMatch((String str)->str.startsWith("a"));
//        System.out.println(flag);
//        stringStream.forEach((String str) -> System.out.println(str));   //末端操作 Stream:325

        /*并行*/

        List<String> arrList=new ArrayList<>();
        for (int i = 0; i < 50000000; i++) {
            strList.add(UUID.randomUUID().toString());
        }

        long s1=System.currentTimeMillis();
        arrList.stream().sorted();                //串行时间:3
        long e1=System.currentTimeMillis();

//        long s=System.currentTimeMillis();
//        arrList.parallelStream().sorted();      //并行时间:14
//        long e=System.currentTimeMillis();

//        System.out.println((e - s));
        System.out.println((e1 - s1));
    }

}
